package com.tensquare.search.server;

import com.tensquare.search.dao.ArticleESRepository;
import com.tensquare.search.dao.pojo.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class ArticleSearchService {
    @Autowired
    private ArticleESRepository articleESRepository;

    /**
     * 保存
     */
    public void save(Article article) {
        this.articleESRepository.save(article);
    }

    /**
     * 根据标题和内容，索引文章列表
     */
    public Page<Article> findArticle(String keywords,  int pageNum, int pageSize) {
        return this.articleESRepository.findByTitleLikeOrContentLike(keywords, keywords, PageRequest.of(pageNum -1 , pageSize));
    }
}
